package cn.jingzhuan.fm.ui.adapter

import android.content.Context
import android.databinding.DataBindingUtil
import android.databinding.ViewDataBinding
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.ViewGroup


abstract class BaseBindingRecyclerAdapter<T> (private val mContext: Context,var list: MutableList<T>) : RecyclerView.Adapter<BindingRecyclerViewHolder>() {

    abstract fun getItemLayoutId(viewType: Int): Int

    abstract fun bindData(holder: BindingRecyclerViewHolder, position: Int, item: T)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):  BindingRecyclerViewHolder{
        var binding = DataBindingUtil.inflate<ViewDataBinding>(LayoutInflater.from(parent.context), getItemLayoutId(viewType), parent, false)
        return BindingRecyclerViewHolder(binding)
    }

    override fun onBindViewHolder(holder: BindingRecyclerViewHolder, position: Int) {
        bindData(holder,position,list[position])
        holder.binding.executePendingBindings()
    }

    override fun getItemCount(): Int = list.size



}